package com.huawei.M01.iterator.M24;

public class DeComposion {
    public int longestDecomposition(String text) {
        // 使用双指针解决问题
        int result = 0;
        while (true) {
            int left = 0;
            int right = text.length() - 1;
            while (left < right && !text.substring(0, left + 1).equals(text.substring(right))) {
                left++;
                right--;
            }

            if (left < right) {
                result += 2;
                text = text.substring(left + 1, right);
            }else {
                result++;
                break;
            }
            if (text.equals("")) {
                break;
            }

        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(new DeComposion().longestDecomposition("elvtoelvto"));
    }
}
